Skip to content

Conversation

@bertsky
Copy link
Contributor

@bertsky bertsky commented Oct 20, 2025

WIP, starting off with regressions from 0.5.0 and old issues (IndexError etc)

TODO:

  • modify return_boxes_of_images_by_order_of_reading_new such that it becomes mildly recursive, in order to avoid cutting through regions: if (for some y slice) some columns have much higher peaks than others, then pick those first and search for new y splitters within the others

Robert Sachunsky added 21 commits October 20, 2025 17:40
(also, simplify `run` and separate `run_single`)
extend horizontal separators to full img width if they do not overlap
any other regions

(only as regards to returned `splitter_y` result,
 but without changing returned separators mask)
regarding `splitter_y` result, for headings, instead of cutting right
through them via center line, add their toplines and baselines as if
they were horizontal separators
- enumeration instead of indexing
- array instead of list operations
- add better plotting (but commented out)
- when handling lines without mother,
  and biggest line already accounts for all columns,
  but some are too close to the top and therefore must be removed,
  avoid invalidating `biggest` index, causing `IndexError`
- remove try-catch (now unnecessary)
- array instead of list operations
simplify and document

- simplify
- rename identifiers to make readable:
  - `y_sep` → `y_mid` (because the cy gets passed)
  - `y_diff` → `y_max` (because the ymax gets passed)
- array instead of list operations
- add docstring and in-line comments
- return (zero-length) numpy array instead of empty list
when calculating `reading_order_type`, upper limit on column range
(`x_end`) needs to be `+1` here as well
- array instead of list operations
- return array of index pairs instead of list objects
- array instead of list operations
- add better plotting (but commented out)
- add more debug printing (but commented out)
- add more inline comments for documentation
- rename identifiers to make more readable:
  - `cy_hor_diff` → `y_max_hor_some` (because the ymax gets passed)
  - `lines` → `seps`
  - `y_type_2` → `y_mid`
  - `y_diff_type_2` → `y_max`
  - `y_lines_by_order` → `y_mid_by_order`
  - `y_lines_without_mother` → `y_mid_without_mother`
  - `y_lines_with_child_without_mother` → `y_mid_with_child_without_mother`
  - `y_column` → `y_mid_column`
  - `y_column_nc` → `y_mid_column_nc`
  - `y_all_between_nm_wc` → `y_mid_between_nm_wc`
  - `lines_so_close_to_top_separator` → `seps_too_close_to_top_separator`
  - `y_in_cols` and `y_down` → `y_mid_next`
- use `pairwise()` `nc_top:nc_bot` instead of `i_c` indexing
when y slice (`top:bot`) is not a significant part of the page,
viz. less than 22% (as in `find_number_of_columns_in_document`),
avoid forcing `find_num_col` to reach `num_col_classifier`

(allows large headers not to be split up and thus better ordered)
(by removing unnecessary conditional)
- use array instead of list operations
- rename identifiers:
  - `pixel` → `label`
  - `line` → `sep`
- drop connected components analysis to test overlaps between
  horizontal separators and (horizontal) neighbours (introduced
  in ab17a92)
- instead of converting headings to topline and baseline during
  `find_number_of_columns_in_document` (introduced in 9f1595d7),
  add them to the matrix unchanged, but mark as extra type
  (besides horizontal and vertical separtors)
- convert headings to toplines and baselines no earlier than in
  `return_boxes_of_images_by_order_of_reading_new`
- for both headings and horizontal separators, if they already
  span multiple columns, check if they would overlap (horizontal)
  neighbours by looking at successively larger (left and right)
  intervals of columns (and pick the largest elongation which
  does not introduce any overlaps)
@bertsky
Copy link
Contributor Author

bertsky commented Oct 25, 2025

Sorry for the force-push! I had accidentally rebased back to a2a06a8 (which now became cd35241).

Still have not addressed the big TODO (which is coming shortly), but found some more useful changes along the way:

  • b2a79cc was clearly a bug
  • 66a0e55 is an improvement: find_num_col should not enforce the overall num_col_classifier result for every part of the page, but rather (as in find_number_of_columns_in_document) only for the big parts, so there would still be room for sections with headings stretching multiple columns
  • 19b2c3f improves on the previous change to elongate horizontal separators if that does not introduce any overlap: now this is done later, when the column split is already determined, so one can also try partial spans; it also covers headings now, but single-column separators/headings are exempt from this now

There are also lots of new plotting directives (commented out). I'll upload some explanatory images next.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant